package com.jixi;

import okhttp3.*;

import java.io.IOException;

public class CozeAPI_AccessToken_TEST {
	public static void main(String[] args) {
		/*
		final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
		MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
		String requestBody = "{\"grant_type\":\"urn:ietf:params:oauth:grant-type:jwt-bearer\",\"duration_seconds\":86399}";
		RequestBody body = RequestBody.Companion.create(requestBody, mediaType);
		Request request = new Request.Builder()
				.url("https://api.coze.cn/api/permission/oauth2/token")
				.post(body)
				.addHeader("Content-Type", "application/json")
				.addHeader("Authorization", "Bearer " + JWT_TEST.getJWTForCoze(1864695777419452418L))
				.build();
		
		try (Response response = HTTP_CLIENT.newCall(request).execute()) {
			if (response.isSuccessful()) {
				if (response.body() != null) {
					String str = response.body().string();
					System.out.println(str);
				}
			} else {
				// 输出错误信息
				if (response.body() != null) {
					System.err.println("请求失败: " + response.code() + " " + response.message());
					System.err.println(response.body().string());
				} else {
					System.err.println("请求失败: " + response.code() + " " + response.message());
				}
			}
		} catch (IOException e) {
			// 捕获网络请求过程中可能发生的IO异常
			System.err.println("请求异常: ");
			e.printStackTrace();
		}
		*/
	}
}
